home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9054 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: nababs@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.lang.c
  4. Subject: Re: Tool for removing surplus #includes
  5. Date: 27 Feb 1996 10:26:09 -0000
  6. Organization: Qualcomm Inc.
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: devitto@ferndown.ate.slb.com
  9. Message-ID: <4gum81$hlk@netlab.cs.rpi.edu>
  10. References: <4gj0p3$lp0@solutions.solon.com>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: 23 Feb 1996 05:12:31 GMT
  13.  
  14. In article <4gj0p3$lp0@solutions.solon.com>, tonyh@tcp.co.uk says...
  15. >
  16. >Does anyone know of a PD tool available with portable(ish) source for
  17. >removing surplus #include directives? For example:
  18. >
  19. >/* "file2.h" */
  20. >#include "file1.h"
  21. >
  22. >-------------------
  23. >
  24. >/* "file3.h" */
  25. >#include "file1.h"
  26. >#include "file2.h"
  27. >
  28. >-------------------
  29. >
  30. >#include "file1.h" could be removed from "file3.h". This sort of thing
  31. >saves a lot of compiler time without having the chore of typing:
  32. >
  33. >#ifndef __file1_h
  34. >#include "file1.h"
  35. >#endif
  36. >
  37.  
  38. So, you mean that in the future if you decide that file2.h do not
  39. need to include file1.h any more, you have to somehow remember 
  40. to go back to file3.h and add a line to include file1.h, since may
  41. be file3.h needs file1.h but file2.h do not need file1.h
  42.  
  43. Having to deal with these sort of things will most likley be not worth
  44. the effort. Also remember that all this work with including .h files
  45. is done by the pre-processor, not by the compiler itself.
  46.  
  47. >
  48. >I know I will still need to do:
  49. >
  50. >/* "file1.h" */
  51. >#ifndef __file1_h
  52. >#define __file1_h
  53. >/* Body of file */
  54. >#endif
  55. >
  56. >but having an additional check around any #include directives or not
  57. >doing the include at all saves the compiler lots of time having to load
  58. >a file it's already included.
  59. >
  60.  
  61. I think you are trying to save few nanoseconds here from the 
  62. pre-processor time, but you will end up instead wasting more time
  63. later when things break during compiling becuase you somewhere
  64. have removed an include statment from one .h file that another file 
  65. needed becuase the other file has including the file that removed the 
  66. include statment from and it has assumed that that file will be there
  67. but it is not in there any more.
  68.  
  69. You also have to remember to "run" this tool every time befor you run
  70. the compiler, which means more tools to woorry about and manage and the
  71. build environment will get more complicated.
  72.  
  73. If I where you, I'll have each .h file include every .h file that it
  74. needs. If one of the files it includes happen to include one of the
  75. files allready, then that is what #ifdef stuff for.
  76.  
  77. Now, others might think this tool is a good idea, I think it is not.
  78.  
  79. IMHO .
  80.  
  81. Nasser
  82.  
  83. { I removed comp.lang.c.moderated from the newsgroups line as crosspostig
  84.   is currently under review -mod}
  85.  
  86.  
  87.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  88.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  89.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  90.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  91.